<template>

  <rx-fit>
    <a-table :columns="columns" :dataSource="data" :pagination="false">
      <span slot="deployed" slot-scope="text,record,index" v-html="formatStyle(text,status)">
      </span>
      <span slot="action" slot-scope="text,record">
          <a v-if="record.main==0" @click="switchMain(record.id)">{{i18n('list.switchMain','切换主版本')}}&nbsp;</a>
          <a @click="createVersion(record.id)">{{i18n('list.createVersion','创建新版本')}}</a>
      </span>
    </a-table>
  </rx-fit>

</template>

<script>

  import FormPcApi from '@/api/form/core/formPc'
  import FormPcEdit from './FormPcEdit'
  import { BaseList, RxLayout,Util } from "@lowcode/jpaas-common-lib"

  export default {
    name: 'FormPcList',
    mixins: [BaseList],
    props:{
      alias:{type:String},
      layerid: {
        type: String,
        default: ""
      },
      destroy: {
        type: Function
      }
    },
    data() {
      return {
        columns: [
          { title: this.i18n('form.name','名称'), dataIndex: 'name', width: '20%' },
          { title: this.i18n('form.alias','别名'), dataIndex: 'alias', width: '20%' },
          { title: this.i18n('form.deployed','发布状态'), dataIndex: 'deployed', width: '20%' ,scopedSlots: { customRender: 'deployed' }},
          { title: this.i18n('form.version','版本号'), dataIndex: 'version', width: '20%' },
          { title: this.$ti18('rxList.action','操作'), width: '20%' , dataIndex: 'action', scopedSlots: { customRender: 'action' } }
        ],
        component: FormPcEdit,
        comment: this.i18n('form.comment','表单'),
        widthHeight: ['800px', '600px'],
        status:[{key:1,text:this.i18n('form.publish','发布'),css:'green'},{key:0,text:this.i18n('form.NotPublish','未发布'),css:'red'}],
        data:[]
      }
    },
    created() {
      this.getVersions()
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"formPc",key);
        },
      getVersions() {
        FormPcApi.getVersions(this.alias).then(res=>{
          this.data=res;
        })
      },
      switchMain(id){
        var self_=this;
        FormPcApi.switchMain(id).then(res=>{
          self_.getVersions();
          self_.$parent.refreshGrid();
        })
      },
      createVersion(id){
        var self_=this;
        this.$layer.confirm(
          self_.i18n('msg.createVersionTips','您确定需要创建表单版本吗？'),{shade: false},
          function(layerid) {
            FormPcApi.createVersion(id).then(res=>{
              self_.getVersions();
              self_.$layer.close(layerid);
            })
          })
      }

    }
  }
</script>
<style  scoped >


</style>

